package com.socket.batch.collector;

import com.socket.batch.deal.IDeal;
import com.socket.batch.deal.DealFactory;
import com.socket.entity.GpsRecord;

/**
 * Created by kaddddd on 2017/7/10 0010.
 */
public abstract class MessageCollector {
    private static IDeal iDeal = null;

    /**
     * 初始工作,用{@link DealFactory}工厂生产了一个指定的处理器实现
     */
    private static void init(){
        if(iDeal!=null){
            return;
        }
        try {
            iDeal = DealFactory.getDeal();
        } catch (Exception e) {

        }
    }

    public static void collect(byte[] gpsBytes){
        GpsRecord gpsRecord = DataAnalysis.analysis(gpsBytes);
        if (iDeal==null){
            synchronized (MessageCollector.class){
                init();
            }
        }
        if(iDeal!=null){
            iDeal.deal(gpsRecord);
        }
    }
}
